package com.wgchao.amc.autho;

import com.wgchao.amc.common.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName: JwtCheck
 * @author: wgchao
 * @createTime: 2019/11/1 1:07 PM
 * @Description: JWT合法性验证
 */
@Component
public class JwtCheck {

    @Autowired
    private UserInfoService userInfoService;

    public UserInfo check(String token) throws Exception{
        String userId = JWTUtil.verifyToken(token, "userId");
        if(userId == null){
            return null;
        }else{
            UserInfo userInfo = userInfoService.getUserInfo(Long.valueOf(userId));
            return userInfo;
        }
    }
}
